package com.web;

import com.dao.Impl.goodDAOImpl;
import com.entity.goods;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author 20x
 * @date 2024 - 11 -20
 **/
@WebServlet("/delGood")
public class DelGoodServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");
        String id = req.getParameter("id");
        int count = new goodDAOImpl().delGood(id);
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();
        if(count > 0){
            List<goods> list = new goodDAOImpl().ListGoods();
            out.write(gson.toJson(list));
        }else{
            out.write(gson.toJson("{\"message\":\"数据接收失败\"}"));
        }
    }
    
}
